package com.example.wuqujingdianphone.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.example.wuqujingdianphone.R;
import com.example.wuqujingdianphone.api.ApiConfig;
import com.example.wuqujingdianphone.base.BaseActivity;
import com.example.wuqujingdianphone.view.X5WebView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class BookWebDetailActivity extends BaseActivity {
    private static final String TAG = "BookWebDetailActivity";
    @BindView(R.id.title)
    TextView mTitle;
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.webView)
    X5WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_book_web_detail);
        ButterKnife.bind(this);

        mTitle.setText("详情");
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        String bookId = getIntent().getStringExtra("bookId");
        Log.i(TAG, "onCreate: bookId=" + bookId);


        //启用硬件加速
        try {
            if (Integer.parseInt(android.os.Build.VERSION.SDK) >= 11) {
                getWindow().setFlags(
                        android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
                        android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
            }
        } catch (Exception e) {
        }


        String type = getIntent().getStringExtra("type");
        if (type != null) {
            if (type.equals("听书馆")) {
                mWebView.loadUrl(ApiConfig.APP_URL + "index.php/Yinpin/show/id/" + bookId + ".shtml");
            } else if (type.equals("体验馆")) {
                mWebView.loadUrl(ApiConfig.APP_URL + "index.php/Video/show/id/" + bookId + ".shtml");
            } else if (type.equals("阅读活动")) {
                mWebView.loadUrl("http://www.wenqujingdian.com/index.php/Huodong");
            }
        }

    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mWebView != null) {
            mWebView.removeAllViews();
            mWebView.clearCache(true);
            mWebView.clearHistory();
            mWebView.destroy();
        }

    }
}
